cmake_minimum_required(VERSION 3.27)

set(CMAKE_CXX_STANDARD 23)

project(LeetCodeSolutions)

# 遍历所有题目文件夹
file(GLOB PROBLEM_FOLDERS "${CMAKE_SOURCE_DIR}/*")

foreach(PROBLEM_FOLDER ${PROBLEM_FOLDERS})
    if(IS_DIRECTORY ${PROBLEM_FOLDER})
        # 获取题号（即文件夹名称）
        get_filename_component(PROBLEM_NUMBER ${PROBLEM_FOLDER} NAME)

        # 检查文件夹名称是否是一个数字（题号）
        string(REGEX MATCH "^[0-9]+$" IS_NUMBER ${PROBLEM_NUMBER})

        if(IS_NUMBER)
            # 查找该文件夹下所有.cpp文件
            file(GLOB_RECURSE PROBLEM_SOURCE_FILES "${PROBLEM_FOLDER}/*.cpp")

            # 创建可执行文件
            add_executable(${PROBLEM_NUMBER} ${PROBLEM_SOURCE_FILES})
        endif()
    endif()
endforeach()